from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-27 14:13:17.616525
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 27, Sep, 2021
Time: 14:13:22
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.3972
Nobs: 427.000 HQIC: -46.9145
Log likelihood: 4725.38 FPE: 3.01044e-21
AIC: -47.2523 Det(Omega_mle): 2.44426e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.424182 0.091595 4.631 0.000
L1.Burgenland 0.105596 0.047449 2.225 0.026
L1.Kärnten -0.113919 0.023793 -4.788 0.000
L1.Niederösterreich 0.162859 0.101659 1.602 0.109
L1.Oberösterreich 0.114982 0.099842 1.152 0.249
L1.Salzburg 0.284577 0.049936 5.699 0.000
L1.Steiermark 0.028772 0.066562 0.432 0.666
L1.Tirol 0.107234 0.052441 2.045 0.041
L1.Vorarlberg -0.103559 0.047047 -2.201 0.028
L1.Wien -0.004623 0.091121 -0.051 0.960
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.012381 0.209789 0.059 0.953
L1.Burgenland -0.050743 0.108676 -0.467 0.641
L1.Kärnten 0.037173 0.054494 0.682 0.495
L1.Niederösterreich -0.213017 0.232838 -0.915 0.360
L1.Oberösterreich 0.490146 0.228677 2.143 0.032
L1.Salzburg 0.306716 0.114373 2.682 0.007
L1.Steiermark 0.107287 0.152452 0.704 0.482
L1.Tirol 0.312503 0.120110 2.602 0.009
L1.Vorarlberg 0.001578 0.107755 0.015 0.988
L1.Wien 0.007753 0.208702 0.037 0.970
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.241824 0.046365 5.216 0.000
L1.Burgenland 0.092241 0.024019 3.840 0.000
L1.Kärnten -0.001845 0.012044 -0.153 0.878
L1.Niederösterreich 0.212003 0.051459 4.120 0.000
L1.Oberösterreich 0.159204 0.050540 3.150 0.002
L1.Salzburg 0.034906 0.025278 1.381 0.167
L1.Steiermark 0.021829 0.033694 0.648 0.517
L1.Tirol 0.068910 0.026546 2.596 0.009
L1.Vorarlberg 0.059174 0.023815 2.485 0.013
L1.Wien 0.113184 0.046125 2.454 0.014
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185709 0.045495 4.082 0.000
L1.Burgenland 0.046494 0.023568 1.973 0.049
L1.Kärnten -0.006577 0.011818 -0.557 0.578
L1.Niederösterreich 0.139715 0.050494 2.767 0.006
L1.Oberösterreich 0.318037 0.049591 6.413 0.000
L1.Salzburg 0.100251 0.024803 4.042 0.000
L1.Steiermark 0.129275 0.033061 3.910 0.000
L1.Tirol 0.077506 0.026047 2.976 0.003
L1.Vorarlberg 0.055852 0.023368 2.390 0.017
L1.Wien -0.046265 0.045260 -1.022 0.307
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.203587 0.090063 2.260 0.024
L1.Burgenland -0.045371 0.046655 -0.972 0.331
L1.Kärnten -0.033995 0.023395 -1.453 0.146
L1.Niederösterreich 0.109753 0.099958 1.098 0.272
L1.Oberösterreich 0.165296 0.098172 1.684 0.092
L1.Salzburg 0.250844 0.049101 5.109 0.000
L1.Steiermark 0.079353 0.065449 1.212 0.225
L1.Tirol 0.124958 0.051564 2.423 0.015
L1.Vorarlberg 0.117178 0.046260 2.533 0.011
L1.Wien 0.032157 0.089597 0.359 0.720
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.033041 0.069444 0.476 0.634
L1.Burgenland 0.023608 0.035974 0.656 0.512
L1.Kärnten 0.054132 0.018039 3.001 0.003
L1.Niederösterreich 0.209499 0.077074 2.718 0.007
L1.Oberösterreich 0.339095 0.075696 4.480 0.000
L1.Salzburg 0.045381 0.037860 1.199 0.231
L1.Steiermark -0.009730 0.050465 -0.193 0.847
L1.Tirol 0.112484 0.039759 2.829 0.005
L1.Vorarlberg 0.069744 0.035669 1.955 0.051
L1.Wien 0.123599 0.069084 1.789 0.074
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195258 0.085127 2.294 0.022
L1.Burgenland 0.015756 0.044098 0.357 0.721
L1.Kärnten -0.057286 0.022112 -2.591 0.010
L1.Niederösterreich -0.115582 0.094480 -1.223 0.221
L1.Oberösterreich 0.192429 0.092791 2.074 0.038
L1.Salzburg 0.033309 0.046410 0.718 0.473
L1.Steiermark 0.285673 0.061861 4.618 0.000
L1.Tirol 0.491269 0.048738 10.080 0.000
L1.Vorarlberg 0.076464 0.043724 1.749 0.080
L1.Wien -0.114543 0.084686 -1.353 0.176
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158016 0.093000 1.699 0.089
L1.Burgenland -0.011343 0.048177 -0.235 0.814
L1.Kärnten 0.063517 0.024157 2.629 0.009
L1.Niederösterreich 0.193754 0.103218 1.877 0.060
L1.Oberösterreich -0.127456 0.101373 -1.257 0.209
L1.Salzburg 0.234697 0.050702 4.629 0.000
L1.Steiermark 0.152390 0.067583 2.255 0.024
L1.Tirol 0.049137 0.053245 0.923 0.356
L1.Vorarlberg 0.131242 0.047768 2.747 0.006
L1.Wien 0.158192 0.092519 1.710 0.087
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.481926 0.050504 9.542 0.000
L1.Burgenland -0.006601 0.026162 -0.252 0.801
L1.Kärnten -0.009701 0.013119 -0.740 0.460
L1.Niederösterreich 0.205351 0.056053 3.664 0.000
L1.Oberösterreich 0.252999 0.055051 4.596 0.000
L1.Salzburg 0.023133 0.027534 0.840 0.401
L1.Steiermark -0.022831 0.036701 -0.622 0.534
L1.Tirol 0.068022 0.028915 2.352 0.019
L1.Vorarlberg 0.060341 0.025940 2.326 0.020
L1.Wien -0.050038 0.050242 -0.996 0.319
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.021973 0.077473 0.139675 0.132741 0.043090 0.073790 0.001749 0.183828
Kärnten 0.021973 1.000000 -0.044271 0.129351 0.047569 0.071397 0.453668 -0.090988 0.090360
Niederösterreich 0.077473 -0.044271 1.000000 0.281718 0.082258 0.268224 0.019668 0.137047 0.260985
Oberösterreich 0.139675 0.129351 0.281718 1.000000 0.177293 0.289273 0.155902 0.101574 0.137630
Salzburg 0.132741 0.047569 0.082258 0.177293 1.000000 0.124645 0.055831 0.106173 0.051091
Steiermark 0.043090 0.071397 0.268224 0.289273 0.124645 1.000000 0.130976 0.093502 -0.016734
Tirol 0.073790 0.453668 0.019668 0.155902 0.055831 0.130976 1.000000 0.046724 0.118625
Vorarlberg 0.001749 -0.090988 0.137047 0.101574 0.106173 0.093502 0.046724 1.000000 -0.046603
Wien 0.183828 0.090360 0.260985 0.137630 0.051091 -0.016734 0.118625 -0.046603 1.000000